package com.kekezu.kppw.data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.tsz.afinal.FinalDb;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

import com.kekezu.kppw.bean.UserBean;
import com.kekezu.kppw.utils.ConfigInc;
import com.kekezu.kppw.utils.HttpUtils;
import com.kekezu.kppw.utils.StrFormat;

@SuppressWarnings("deprecation")
public class TaskData {
	static Intent intent;
	static FinalDb db;

	/**
	 * 首页任务
	 * 
	 * @param context
	 * @return
	 */
	public static ArrayList<HashMap<String, Object>> getIndexTask(
			Context context) {
		ArrayList<HashMap<String, Object>> aliList = new ArrayList<HashMap<String, Object>>();

		String urlString = ConfigInc.getServiceAdress(context) + "task/hotTask";
		HttpUtils httpUtils = HttpUtils.getInstance();

		try {
			String strJson = httpUtils.httpGet(urlString, context);
			// Log.e("strJson", strJson);

			JSONObject jsonObject = new JSONObject(strJson);

			String resString = jsonObject.getString("code");

			// 对返回的数据进行判断
			if (resString.equals("1000")) {
				JSONArray jsonArray = jsonObject.getJSONArray("data");

				for (int i = 0; i < jsonArray.length(); i++) {
					HashMap<String, Object> map = new HashMap<String, Object>();
					JSONObject itemJsonObject = jsonArray.optJSONObject(i);

					map.put("id", itemJsonObject.getString("id"));
					map.put("title", itemJsonObject.getString("title"));
					map.put("bounty", itemJsonObject.getString("bounty"));
					map.put("created_at", itemJsonObject
							.getString("created_at").substring(0, 10));
					map.put("view_count",
							itemJsonObject.getString("view_count"));
					map.put("delivery_count",
							itemJsonObject.getString("delivery_count"));

					map.put("cate_name", itemJsonObject.getString("name"));
					map.put("task_type", itemJsonObject.getString("task_type"));
					map.put("task_service",
							itemJsonObject.getString("task_service"));
					if (itemJsonObject.getString("bounty_status").equals("0")) {
						map.put("bounty_status_desc", "未托管");
					} else {
						map.put("bounty_status_desc", "已托管");
					}

					aliList.add(map);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return aliList;
	}

	/**
	 * 任务大厅
	 * 
	 * @param cateId
	 * @param tpye
	 * @param page
	 * @param strName
	 * @param context
	 * @return
	 */
	public static ArrayList<HashMap<String, Object>> getTask(String cateId,
			int tpye, int page, String strName, String strDesc, Context context) {
		ArrayList<HashMap<String, Object>> taskList = new ArrayList<HashMap<String, Object>>();
		String urlString = ConfigInc.getServiceAdress(context) + "tasks?";
		HttpUtils httpUtils = HttpUtils.getInstance();

		Map<String, String> params = new HashMap<String, String>();

		params.put("cate_id", cateId);
		params.put("type", "" + tpye);
		params.put("page", "" + page);
		params.put("taskName", strName);
		params.put("desc", strDesc);

		try {
			String strJson = httpUtils.httpGet(urlString, params, context);
			// Log.e("strJson", strJson);
			JSONObject jsonObject = new JSONObject(strJson);
			String resCode = jsonObject.getString("code");

			JSONObject jsonData = jsonObject.getJSONObject("data");
			JSONArray jsonArray = jsonData.getJSONArray("data");

			// if (jsonArray.length() <= 0)
			// {
			// jsonArray = jsonData.getJSONArray("recommend");
			// }

			// 对返回的数据进行判断
			if (resCode.equals("1000")) {
				for (int i = 0; i < jsonArray.length(); i++) {
					HashMap<String, Object> map = new HashMap<String, Object>();
					JSONObject itemJsonObject = jsonArray.optJSONObject(i);

					map.put("id", itemJsonObject.getString("id"));
					map.put("title", itemJsonObject.getString("title"));
					map.put("view_count",
							itemJsonObject.getString("view_count"));
					map.put("delivery_count",
							itemJsonObject.getString("delivery_count"));
					map.put("created_at", itemJsonObject
							.getString("created_at").substring(0, 10));
					map.put("bounty", itemJsonObject.getString("bounty"));
					map.put("bounty_status",
							itemJsonObject.getString("bounty_status"));// 托管状态
																		// 1:已托管
																		// 0:未托管
					map.put("bounty_status_desc",
							itemJsonObject.getString("bounty_status_desc"));

					if (StrFormat.formatStr(itemJsonObject.getString("name"))) {
						map.put("cate_name", itemJsonObject.getString("name"));
					} else {
						map.put("cate_name", "暂无");
					}
					map.put("uid", itemJsonObject.getString("uid"));
					map.put("task_type", itemJsonObject.getString("task_type"));
					map.put("task_service",
							itemJsonObject.getString("task_service"));
					taskList.add(map);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return taskList;
	}

	public static Map<String, String> getTask222(String cateId, int tpye,
			int page, String strName, String strDesc, Context context) {
		Map<String, String> taskList = new HashMap<String, String>();
		String urlString = ConfigInc.getServiceAdress(context) + "tasks?";
		HttpUtils httpUtils = HttpUtils.getInstance();

		Map<String, String> params = new HashMap<String, String>();
		params.put("cate_id", cateId);
		params.put("type", "" + tpye);
		params.put("page", "" + page);
		params.put("taskName", strName);
		params.put("desc", strDesc);

		try {
			String strJson = httpUtils.httpGet(urlString, params, context);
			// Log.e("strJson", strJson);
			JSONObject jsonObject = new JSONObject(strJson);
			JSONObject jsonData = jsonObject.getJSONObject("data");
			taskList.put("data", jsonData.get("data").toString());
			if (jsonData.getJSONArray("data").length() <= 0) {
				taskList.put("datasize", "0");
				taskList.put("recommend", jsonData.get("recommend").toString());
			} else {
				taskList.put("datasize", "1");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return taskList;
	}

	public static ArrayList<HashMap<String, Object>> getTask333(String str) {
		ArrayList<HashMap<String, Object>> taskList = new ArrayList<HashMap<String, Object>>();
		try {
			JSONArray jsonArray = new JSONArray(str);
			for (int i = 0; i < jsonArray.length(); i++) {
				HashMap<String, Object> map = new HashMap<String, Object>();
				JSONObject itemJsonObject = jsonArray.optJSONObject(i);

				map.put("id", itemJsonObject.getString("id"));
				map.put("title", itemJsonObject.getString("title"));
				map.put("view_count", itemJsonObject.getString("view_count"));
				map.put("delivery_count",
						itemJsonObject.getString("delivery_count"));
				map.put("created_at", itemJsonObject.getString("created_at")
						.substring(0, 10));
				map.put("bounty", itemJsonObject.getString("bounty"));
				map.put("bounty_status",
						itemJsonObject.getString("bounty_status"));
				map.put("bounty_status_desc",
						itemJsonObject.getString("bounty_status_desc"));
				if (StrFormat.formatStr(itemJsonObject.getString("name"))) {
					map.put("cate_name", itemJsonObject.getString("name"));
				} else {
					map.put("cate_name", "暂无");
				}
				map.put("uid", itemJsonObject.getString("uid"));
				map.put("task_type", itemJsonObject.getString("task_type"));
				map.put("task_service",
						itemJsonObject.getString("task_service"));

				taskList.add(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return taskList;
	}

	// 编辑任务
	public static Map<String, String> editTask(String taskId, Context context) {
		Map<String, String> resMap = new HashMap<String, String>();
		String urlString = ConfigInc.getServiceAdress(context)
				+ "myTask/editTask?";
		HttpUtils httpUtils = HttpUtils.getInstance();

		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);

		Map<String, String> params = new HashMap<String, String>();
		params.put("id", taskId);
		params.put("token", "" + users.get(0).getToken());

		try {
			String strJson = httpUtils.httpGet(urlString, params, context);
			JSONObject jsonObject = new JSONObject(strJson);

			resMap.put("code", jsonObject.getString("code"));
			resMap.put("message", jsonObject.getString("message"));

			JSONObject jsondata = new JSONObject(jsonObject.getString("data"));
			resMap.put("id", jsondata.getString("id"));// 任务id
			resMap.put("title", jsondata.getString("title"));// 标题
			resMap.put("desc", jsondata.getString("desc"));// 详情
			resMap.put("cate_id", jsondata.getString("cate_id"));
			resMap.put("phone", jsondata.getString("phone"));
			resMap.put("status", jsondata.getString("status"));
			resMap.put("bounty", jsondata.getString("bounty"));
			resMap.put("bounty_status", jsondata.getString("bounty_status"));
			resMap.put("created_at", jsondata.getString("created_at"));
			resMap.put("begin_at", jsondata.getString("begin_at"));
			resMap.put("view_count", jsondata.getString("view_count"));// 浏览量
			resMap.put("delivery_count", jsondata.getString("delivery_count"));
			resMap.put("province", jsondata.getString("province"));
			resMap.put("city", jsondata.getString("city"));
			resMap.put("area", jsondata.getString("area"));
			resMap.put("uid", jsondata.getString("uid"));
			resMap.put("worker_num", jsondata.getString("worker_num"));
			resMap.put("cate_name", jsondata.getString("cate_name"));
			resMap.put("task_type", jsondata.getString("task_type"));
			resMap.put("attachment", jsondata.getString("attachment"));
			resMap.put("province_name", jsondata.getString("province_name"));
			resMap.put("city_name", jsondata.getString("city_name"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return resMap;
	}

	/**
	 * 任务详情
	 * 
	 * @param taskId
	 * @param context
	 * @return
	 */
	public static Map<String, String> getTaskDetails(String taskId,
			Context context) {
		Map<String, String> resMap = new HashMap<String, String>();
		String urlString = ConfigInc.getServiceAdress(context)
				+ "myTask/detail?";
		HttpUtils httpUtils = HttpUtils.getInstance();

		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);

		Map<String, String> params = new HashMap<String, String>();
		params.put("id", taskId);
		if (users.size() > 0) {
			params.put("token", "" + users.get(0).getToken());
		}

		try {
			String strJson = httpUtils.httpGet(urlString, params, context);
			JSONObject jsonObject = new JSONObject(strJson);

			resMap.put("code", jsonObject.getString("code"));
			resMap.put("message", jsonObject.getString("message"));
			// 对返回的数据进行判断
			if (jsonObject.getString("code").equals("1000")) {
				JSONObject jsondata = new JSONObject(
						jsonObject.getString("data"));
				resMap.put("id", jsondata.getString("id"));// 任务id
				resMap.put("title", jsondata.getString("title"));// 标题
				resMap.put("desc", jsondata.getString("desc"));// 详情
				resMap.put("phone", jsondata.getString("phone"));
				resMap.put("status", jsondata.getString("status"));
				resMap.put("bounty", jsondata.getString("bounty"));
				resMap.put("bounty_status", jsondata.getString("bounty_status"));
				resMap.put("created_at", jsondata.getString("created_at"));
				resMap.put("begin_at", jsondata.getString("begin_at"));
				resMap.put("view_count", jsondata.getString("view_count"));// 浏览量
				resMap.put("delivery_count",
						jsondata.getString("delivery_count"));
				resMap.put("uid", jsondata.getString("uid"));
				resMap.put("worker_num", jsondata.getString("worker_num"));
				resMap.put("top_status", jsondata.getString("top_status"));
				resMap.put("engine_status", jsondata.getString("engine_status"));
				resMap.put("work_status", jsondata.getString("work_status"));
				resMap.put("cate_name", jsondata.getString("cate_name"));
				resMap.put("type_name", jsondata.getString("type_name"));
				resMap.put("task_type", jsondata.getString("task_type"));
				resMap.put("bidnum", jsondata.getString("bidnum"));
				resMap.put("bounty_status_desc",
						jsondata.getString("bounty_status_desc"));
				resMap.put("focused", jsondata.getString("focused"));
				resMap.put("name", jsondata.getString("name"));
				resMap.put("attachment", jsondata.getString("attachment"));
				resMap.put("city_name", jsondata.getString("city_name"));
				resMap.put("status_desc", jsondata.getString("status_desc"));
				resMap.put("time_desc", jsondata.getString("time_desc"));
				resMap.put("role", jsondata.getString("role"));
				resMap.put("employee_button",
						jsondata.getString("employee_button"));
				resMap.put("employee_button_desc",
						jsondata.getString("employee_button_desc"));
				resMap.put("employer_button",
						jsondata.getString("employer_button"));
				resMap.put("employer_button_desc",
						jsondata.getString("employer_button_desc"));
				resMap.put("task_service", jsondata.getString("task_service"));
				resMap.put("delivery_sort", jsondata.getString("delivery_sort"));
				resMap.put("delivery_work_id",
						jsondata.getString("delivery_work_id"));
				resMap.put("to_comment_name",
						jsondata.getString("to_comment_name"));
				resMap.put("to_comment_avatar",
						jsondata.getString("to_comment_avatar"));
				resMap.put("work_list_desc",
						jsondata.getString("work_list_desc"));
				resMap.put("work_list_count",
						jsondata.getString("work_list_count"));
				resMap.put("work_list", jsondata.getString("work_list"));
				resMap.put("delivery_list_desc",
						jsondata.getString("delivery_list_desc"));
				resMap.put("delivery_list_count",
						jsondata.getString("delivery_list_count"));
				resMap.put("right_list_desc",
						jsondata.getString("right_list_desc"));
				resMap.put("right_list_count",
						jsondata.getString("right_list_count"));
				resMap.put("comment_list_desc",
						jsondata.getString("comment_list_desc"));
				resMap.put("comment_list_count",
						jsondata.getString("comment_list_count"));

			} else {
				Toast.makeText(context, "请求异常", Toast.LENGTH_SHORT).show();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return resMap;
	}

	/**
	 * 任务详情附件
	 * 
	 * @param str
	 * @return
	 */
	public static ArrayList<HashMap<String, Object>> getAttachment(String str) {
		ArrayList<HashMap<String, Object>> attachmentList = new ArrayList<HashMap<String, Object>>();
		try {
			// JSONObject jsonObject = new JSONObject(str);
			JSONArray jsonArray = new JSONArray(str);

			for (int i = 0; i < jsonArray.length(); i++) {
				HashMap<String, Object> map = new HashMap<String, Object>();
				JSONObject itemJsonObject = jsonArray.optJSONObject(i);
				map.put("id", itemJsonObject.getString("id"));
				map.put("url", itemJsonObject.getString("url"));
				map.put("name", itemJsonObject.getString("name"));
				map.put("type", itemJsonObject.getString("type"));
				map.put("status", itemJsonObject.getString("status"));
				attachmentList.add(map);
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}

		return attachmentList;
	}

	/**
	 * 任务详情的任务稿件
	 * 
	 * @param str
	 * @return
	 */
	public static ArrayList<HashMap<String, Object>> getWorkInfo(String str) {
		ArrayList<HashMap<String, Object>> workList = new ArrayList<HashMap<String, Object>>();
		try {
			JSONArray jsonArray = new JSONArray(str);

			for (int i = 0; i < jsonArray.length(); i++) {
				HashMap<String, Object> map = new HashMap<String, Object>();
				JSONObject itemJsonObject = jsonArray.optJSONObject(i);

				map.put("id", itemJsonObject.getString("id"));
				map.put("uid", itemJsonObject.getString("uid"));
				map.put("desc", itemJsonObject.getString("desc"));
				map.put("status", itemJsonObject.getString("status"));
				map.put("nickname", itemJsonObject.getString("nickname"));
				map.put("avatar", itemJsonObject.getString("avatar"));
				map.put("percent", itemJsonObject.getString("percent"));
				map.put("created_at", itemJsonObject.getString("created_at"));
				map.put("delivery_sort", "");

				if (StrFormat.formatStr(itemJsonObject.getString("price")
						.toString())) {
					map.put("price", itemJsonObject.getString("price")
							.toString());
				} else {
					map.put("price", "");
				}

				map.put("percent", itemJsonObject.getString("percent"));

				workList.add(map);
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}

		return workList;
	}

	public static ArrayList<HashMap<String, Object>> deliveryList(String id,
			Context context) {
		ArrayList<HashMap<String, Object>> taskList = new ArrayList<HashMap<String, Object>>();
		String urlString = ConfigInc.getServiceAdress(context)
				+ "task/deliveryList?";
		HttpUtils httpUtils = HttpUtils.getInstance();

		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);

		Map<String, String> params = new HashMap<String, String>();
		params.put("id", id);
		if (users.size() > 0) {
			params.put("token", users.get(0).getToken());
		}

		try {
			String strJson = httpUtils.httpGet(urlString, params, context);
			JSONObject jsonObject = new JSONObject(strJson);
			String resCode = jsonObject.getString("code");

			// 对返回的数据进行判断
			if (resCode.equals("1000")) {
				JSONArray jsonArray = jsonObject.getJSONArray("data");
				for (int i = 0; i < jsonArray.length(); i++) {
					HashMap<String, Object> map = new HashMap<String, Object>();
					JSONObject itemJsonObject = jsonArray.optJSONObject(i);

					map.put("id", itemJsonObject.getString("id"));
					map.put("uid", itemJsonObject.getString("uid"));
					map.put("desc", itemJsonObject.getString("desc"));
					map.put("status", itemJsonObject.getString("status"));
					map.put("nickname", itemJsonObject.getString("nickname"));
					map.put("avatar", itemJsonObject.getString("avatar"));
					map.put("percent", itemJsonObject.getString("percent"));
					map.put("created_at",
							itemJsonObject.getString("created_at"));
					map.put("delivery_sort",
							itemJsonObject.getString("delivery_sort"));
					map.put("price", "");
					taskList.add(map);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return taskList;
	}

	public static ArrayList<HashMap<String, Object>> rightList(String id,
			Context context) {
		ArrayList<HashMap<String, Object>> taskList = new ArrayList<HashMap<String, Object>>();
		String urlString = ConfigInc.getServiceAdress(context)
				+ "task/rightList?";
		HttpUtils httpUtils = HttpUtils.getInstance();

		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);

		Map<String, String> params = new HashMap<String, String>();
		params.put("id", id);
		if (users.size() > 0) {
			params.put("token", users.get(0).getToken());
		}

		try {
			String strJson = httpUtils.httpGet(urlString, params, context);
			JSONObject jsonObject = new JSONObject(strJson);
			String resCode = jsonObject.getString("code");

			// 对返回的数据进行判断
			if (resCode.equals("1000")) {
				JSONArray jsonArray = jsonObject.getJSONArray("data");
				for (int i = 0; i < jsonArray.length(); i++) {
					HashMap<String, Object> map = new HashMap<String, Object>();
					JSONObject itemJsonObject = jsonArray.optJSONObject(i);

					map.put("id", itemJsonObject.getString("id"));
					map.put("uid", itemJsonObject.getString("uid"));
					map.put("desc", "");
					map.put("status", itemJsonObject.getString("status"));
					map.put("nickname", itemJsonObject.getString("nickname"));
					map.put("avatar", itemJsonObject.getString("avatar"));
					map.put("percent", itemJsonObject.getString("percent"));
					map.put("created_at",
							itemJsonObject.getString("created_at"));

					map.put("delivery_sort", "");
					map.put("price", "");

					taskList.add(map);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return taskList;
	}

	public static ArrayList<HashMap<String, String>> commentList(String id,
			Context context) {
		ArrayList<HashMap<String, String>> taskList = new ArrayList<HashMap<String, String>>();
		String urlString = ConfigInc.getServiceAdress(context)
				+ "task/commentList?";
		HttpUtils httpUtils = HttpUtils.getInstance();

		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);

		Map<String, String> params = new HashMap<String, String>();
		params.put("id", id);
		if (users.size() > 0) {
			params.put("token", users.get(0).getToken());
		}

		try {
			String strJson = httpUtils.httpGet(urlString, params, context);
			JSONObject jsonObject = new JSONObject(strJson);
			String resCode = jsonObject.getString("code");

			Log.e("1123", strJson);

			// 对返回的数据进行判断
			if (resCode.equals("1000")) {
				JSONArray jsonArray = jsonObject.getJSONArray("data");
				for (int i = 0; i < jsonArray.length(); i++) {
					HashMap<String, String> map = new HashMap<String, String>();
					JSONObject itemJsonObject = jsonArray.optJSONObject(i);

					map.put("id", itemJsonObject.getString("id"));
					map.put("task_id", itemJsonObject.getString("task_id"));
					map.put("from_uid", itemJsonObject.getString("from_uid"));
					map.put("to_uid", itemJsonObject.getString("to_uid"));
					map.put("comment", itemJsonObject.getString("comment"));
					map.put("comment_by",
							itemJsonObject.getString("comment_by"));
					map.put("speed_score",
							itemJsonObject.getString("speed_score"));
					map.put("quality_score",
							itemJsonObject.getString("quality_score"));
					map.put("attitude_score",
							itemJsonObject.getString("attitude_score"));
					map.put("type", itemJsonObject.getString("type"));
					map.put("created_at",
							itemJsonObject.getString("created_at"));
					map.put("uid", itemJsonObject.getString("uid"));
					map.put("nickname", itemJsonObject.getString("nickname"));
					map.put("avatar", itemJsonObject.getString("avatar"));
					map.put("to_desc", itemJsonObject.getString("to_desc"));
					map.put("to_status", itemJsonObject.getString("to_status"));

					taskList.add(map);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return taskList;
	}

	// 招标任务查看付款方式
	public static Map<String, String> paySection(String taskId, Context context) {
		Map<String, String> resMap = new HashMap<String, String>();
		String urlString = ConfigInc.getServiceAdress(context)
				+ "myTask/paySection?";
		HttpUtils httpUtils = HttpUtils.getInstance();

		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);

		Map<String, String> params = new HashMap<String, String>();
		params.put("id", taskId);
		params.put("token", "" + users.get(0).getToken());

		try {
			String strJson = httpUtils.httpGet(urlString, params, context);
			JSONObject jsonObject = new JSONObject(strJson);
			resMap.put("code", jsonObject.getString("code"));
			resMap.put("message", jsonObject.getString("message"));
			// 对返回的数据进行判断
			if (jsonObject.getString("code").equals("1000")) {
				JSONObject jsondata = new JSONObject(
						jsonObject.getString("data"));
				resMap.put("role", jsondata.getString("role"));
				resMap.put("pay_type_status",
						jsondata.getString("pay_type_status"));
				resMap.put("task_bounty", jsondata.getString("task_bounty"));
				resMap.put("pay_type", jsondata.getString("pay_type"));
				resMap.put("pay_type_append",
						jsondata.getString("pay_type_append"));
				resMap.put("pay_section", jsondata.getString("pay_section"));// 支付阶段数组
			} else {
				Toast.makeText(context, "请求异常", Toast.LENGTH_SHORT).show();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return resMap;
	}

	// 招标任务阶段列表
	public static ArrayList<HashMap<String, Object>> getPaySection(String str) {
		ArrayList<HashMap<String, Object>> workList = new ArrayList<HashMap<String, Object>>();
		try {
			JSONArray jsonArray = new JSONArray(str);

			for (int i = 0; i < jsonArray.length(); i++) {
				HashMap<String, Object> map = new HashMap<String, Object>();
				JSONObject itemJsonObject = jsonArray.optJSONObject(i);
				map.put("name", itemJsonObject.getString("name"));
				map.put("sort", itemJsonObject.getString("sort"));
				map.put("percent", itemJsonObject.getString("percent"));
				map.put("price", itemJsonObject.getString("price"));
				map.put("desc", itemJsonObject.getString("desc").toString());
				workList.add(map);
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}

		return workList;
	}

	/**
	 * 雇主的任务列表
	 * 
	 * @param status
	 * @param page
	 * @param context
	 * @return
	 */
	public static ArrayList<HashMap<String, Object>> getGoodTask(int status,
			int page, String type, Context context) {
		ArrayList<HashMap<String, Object>> taskList = new ArrayList<HashMap<String, Object>>();
		String urlString = ConfigInc.getServiceAdress(context)
				+ "myTask/index?";
		HttpUtils httpUtils = HttpUtils.getInstance();

		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);

		Map<String, String> params = new HashMap<String, String>();

		params.put("status", String.valueOf(status));
		params.put("type", type);
		params.put("token", users.get(0).getToken());
		params.put("page", String.valueOf(page));

		try {
			String strJson = httpUtils.httpGet(urlString, params, context);
			JSONObject jsonObject = new JSONObject(strJson);
			String resCode = jsonObject.getString("code");

			// 对返回的数据进行判断
			if (resCode.equals("1000")) {
				JSONObject jsondata = new JSONObject(
						jsonObject.getString("data"));
				JSONArray jsonArray = jsondata.getJSONArray("data");

				if (jsonArray.length() > 0) {
					for (int i = 0; i < jsonArray.length(); i++) {
						HashMap<String, Object> map = new HashMap<String, Object>();
						JSONObject itemJsonObject = jsonArray.optJSONObject(i);

						map.put("id", itemJsonObject.getString("id"));
						map.put("title", itemJsonObject.getString("title"));
						map.put("bounty", itemJsonObject.getString("bounty"));
						map.put("bounty_status_desc",
								itemJsonObject.getString("bounty_status_desc"));
						map.put("task_service",
								itemJsonObject.getString("task_service"));
						map.put("view_count",
								itemJsonObject.getString("view_count"));
						map.put("delivery_count",
								itemJsonObject.getString("delivery_count"));
						map.put("created_at",
								itemJsonObject.getString("begin_at").substring(
										0, 10));
						map.put("cate_name",
								itemJsonObject.getString("cate_name"));
						map.put("task_type",
								itemJsonObject.getString("task_type"));
						// Log.e("", msg);

						taskList.add(map);
					}
				} else {
					Toast.makeText(context, "无数据", Toast.LENGTH_SHORT).show();
				}
			} else {
				Toast.makeText(context, "请求异常", Toast.LENGTH_SHORT).show();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return taskList;
	}

	/**
	 * 威客的任务列表
	 * 
	 * @param status
	 * @param page
	 * @param context
	 * @return
	 */
	public static ArrayList<HashMap<String, Object>> getWitkeyTask(int status,
			int page, String type, Context context) {
		ArrayList<HashMap<String, Object>> taskList = new ArrayList<HashMap<String, Object>>();
		String urlString = ConfigInc.getServiceAdress(context)
				+ "myTask/myAccept?";
		HttpUtils httpUtils = HttpUtils.getInstance();

		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);

		Map<String, String> params = new HashMap<String, String>();
		params.put("status", String.valueOf(status));
		params.put("token", users.get(0).getToken());
		params.put("page", String.valueOf(page));
		params.put("type", type);

		try {
			String strJson = httpUtils.httpGet(urlString, params, context);
			JSONObject jsonObject = new JSONObject(strJson);
			String resCode = jsonObject.getString("code");

			// 对返回的数据进行判断
			if (resCode.equals("1000")) {
				JSONObject jsondata = new JSONObject(
						jsonObject.getString("data"));
				JSONArray jsonArray = jsondata.getJSONArray("data");

				if (jsonArray.length() > 0) {
					for (int i = 0; i < jsonArray.length(); i++) {
						HashMap<String, Object> map = new HashMap<String, Object>();
						JSONObject itemJsonObject = jsonArray.optJSONObject(i);

						map.put("id", itemJsonObject.getString("id"));
						map.put("title", itemJsonObject.getString("title"));
						map.put("bounty", itemJsonObject.getString("bounty"));
						map.put("view_count",
								itemJsonObject.getString("view_count"));
						map.put("delivery_count",
								itemJsonObject.getString("delivery_count"));
						map.put("created_at",
								itemJsonObject.getString("begin_at").substring(
										0, 10));
						map.put("bounty_status_desc",
								itemJsonObject.getString("bounty_status_desc"));
						map.put("task_service",
								itemJsonObject.getString("task_service"));
						map.put("cate_name",
								itemJsonObject.getString("service"));
						map.put("task_type",
								itemJsonObject.getString("task_type"));
						// Log.e("", msg);

						taskList.add(map);
					}
				}
			} else {
				Toast.makeText(context, "请求异常", Toast.LENGTH_SHORT).show();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return taskList;
	}

	/**
	 * 创建任务
	 */
	public static String[] creationTask(String strTaskid, String strTitle,
			String strDesc, String strCateId, String strBounty,
			String strWorkerNum, String strProvince, String strCity,
			String strDelivery, String strStatus, String strFileId,
			String strBeginAt, String strPhone, String strTaskType,
			String strSerId, Context context) {
		String strData[] = new String[3];
		String urlString = ConfigInc.getServiceAdress(context)
				+ "myTask/createTask";
		HttpUtils httpUtils = HttpUtils.getInstance();

		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);

		List<NameValuePair> params = new ArrayList<NameValuePair>();
		if (StrFormat.formatStr(strTaskid)) {
			params.add(new BasicNameValuePair("task_id", strTaskid));
		}
		params.add(new BasicNameValuePair("title", strTitle));
		params.add(new BasicNameValuePair("desc", strDesc));
		params.add(new BasicNameValuePair("cate_id", strCateId));
		params.add(new BasicNameValuePair("bounty", strBounty));
		params.add(new BasicNameValuePair("worker_num", strWorkerNum));
		params.add(new BasicNameValuePair("province", strProvince));
		params.add(new BasicNameValuePair("city", strCity));
		params.add(new BasicNameValuePair("delivery_deadline", strDelivery));
		params.add(new BasicNameValuePair("token", users.get(0).getToken()));
		params.add(new BasicNameValuePair("status", strStatus));
		if (StrFormat.formatStr(strFileId)) {
			params.add(new BasicNameValuePair("file_id", strFileId));
		}

		params.add(new BasicNameValuePair("begin_at", strBeginAt));
		params.add(new BasicNameValuePair("phone", strPhone));
		params.add(new BasicNameValuePair("type_id", strTaskType));
		params.add(new BasicNameValuePair("service_id", strSerId));

		try {
			String strJson = httpUtils.executeRequest(urlString, params);
			JSONObject jsonObject = new JSONObject(strJson);
			Log.e("strjson", strJson);

			strData[0] = jsonObject.getString("code");
			strData[1] = jsonObject.getString("message");
			// 对返回的数据进行判断
			if (jsonObject.getString("code").equals("1000")) {
				strData[2] = jsonObject.getString("data");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return strData;
	}

	public static String bountyBidTask(String strid, Context context) {
		String strData = "";
		String urlString = ConfigInc.getServiceAdress(context)
				+ "myTask/bountyBidTask?";
		HttpUtils httpUtils = HttpUtils.getInstance();

		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);

		Map<String, String> params = new HashMap<String, String>();
		params.put("id", strid);
		params.put("token", users.get(0).getToken());

		try {
			String strJson = httpUtils.httpGet(urlString, params, context);
			JSONObject jsonObject = new JSONObject(strJson);
			strData = jsonObject.getString("data");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return strData;
	}

	// 任务发布成功返回参数解析
	public static Map<String, String> getTaskBill(String string) {
		Map<String, String> task_ser = new HashMap<String, String>();
		try {
			JSONObject jsonObject = new JSONObject(string);

			task_ser.put("task_id", jsonObject.getString("task_id"));
			task_ser.put("title", jsonObject.getString("title"));
			task_ser.put("balance", jsonObject.getString("balance"));
			task_ser.put("money", jsonObject.getString("money"));
			task_ser.put("create_order", jsonObject.getString("create_order"));

			JSONObject jsonInfo = jsonObject.getJSONObject("task_info");

			task_ser.put("id", jsonInfo.getString("id"));
			task_ser.put("title", jsonInfo.getString("title"));
			task_ser.put("desc", jsonInfo.getString("desc"));
			task_ser.put("type_id", jsonInfo.getString("type_id"));
			task_ser.put("cate_id", jsonInfo.getString("cate_id"));
			task_ser.put("phone", jsonInfo.getString("phone"));
			task_ser.put("region_limit", jsonInfo.getString("region_limit"));
			task_ser.put("status", jsonInfo.getString("status"));
			task_ser.put("bounty", jsonInfo.getString("bounty"));
			task_ser.put("bounty_status", jsonInfo.getString("bounty_status"));
			task_ser.put("created_at", jsonInfo.getString("created_at"));
			task_ser.put("begin_at", jsonInfo.getString("begin_at"));
			task_ser.put("end_at", jsonInfo.getString("end_at"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return task_ser;
	}

	/**
	 * 获取增值服务
	 */
	public static ArrayList<HashMap<String, String>> getTaskService(
			Context context) {
		ArrayList<HashMap<String, String>> task_ser = new ArrayList<HashMap<String, String>>();

		String urlString = ConfigInc.getServiceAdress(context)
				+ "myTask/gettaskService?";
		HttpUtils httpUtils = HttpUtils.getInstance();

		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);

		Map<String, String> params = new HashMap<String, String>();
		params.put("token", "" + users.get(0).getToken());

		try {
			String strJson = httpUtils.httpGet(urlString, params, context);
			JSONObject jsonObject = new JSONObject(strJson);
			String resCode = jsonObject.getString("code");

			Log.e("strjson", strJson);

			// 对返回的数据进行判断
			if (resCode.equals("1000")) {
				JSONArray jsonArray = jsonObject.getJSONArray("data");

				for (int i = 0; i < jsonArray.length(); i++) {
					HashMap<String, String> map = new HashMap<String, String>();
					JSONObject itemJsonObject = jsonArray.optJSONObject(i);

					map.put("id", itemJsonObject.getString("id"));
					map.put("title", itemJsonObject.getString("title"));
					map.put("price", itemJsonObject.getString("price"));
					map.put("identify", itemJsonObject.getString("identify"));

					task_ser.add(map);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return task_ser;
	}

	/**
	 * 任务草稿箱
	 * 
	 * @param page
	 * @param context
	 * @return
	 */
	public static ArrayList<HashMap<String, Object>> getTaskDraft(int page,
			Context context) {
		ArrayList<HashMap<String, Object>> taskList = new ArrayList<HashMap<String, Object>>();
		String urlString = ConfigInc.getServiceAdress(context) + "noPubTask?";
		HttpUtils httpUtils = HttpUtils.getInstance();

		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);

		Map<String, String> params = new HashMap<String, String>();
		params.put("page", "" + page);
		params.put("token", "" + users.get(0).getToken());

		try {
			String strJson = httpUtils.httpGet(urlString, params, context);
			JSONObject jsonObject = new JSONObject(strJson);
			String resCode = jsonObject.getString("code");

			// 对返回的数据进行判断
			if (resCode.equals("1000")) {
				String resData = jsonObject.getString("data");
				JSONObject jsondata = new JSONObject(resData);
				JSONArray jsonArray = jsondata.getJSONArray("data");

				for (int i = 0; i < jsonArray.length(); i++) {
					HashMap<String, Object> map = new HashMap<String, Object>();
					JSONObject itemJsonObject = jsonArray.optJSONObject(i);

					map.put("id", itemJsonObject.getString("id"));
					map.put("title", itemJsonObject.getString("title"));
					map.put("task_type", itemJsonObject.getString("task_type"));
					map.put("desc", itemJsonObject.getString("desc"));
					map.put("cate_id", itemJsonObject.getString("cate_id"));
					map.put("task_service",
							itemJsonObject.getString("task_service"));
					map.put("bounty", itemJsonObject.getString("bounty"));
					map.put("bounty_status_desc",
							itemJsonObject.getString("bounty_status_desc"));
					map.put("phone", itemJsonObject.getString("phone"));
					map.put("worker_num",
							itemJsonObject.getString("worker_num"));
					map.put("province", itemJsonObject.getString("province"));
					map.put("city", itemJsonObject.getString("city"));
					map.put("cate_id", itemJsonObject.getString("cate_id"));
					map.put("cate_name", itemJsonObject.getString("cate_name"));
					map.put("begin_at", itemJsonObject.getString("begin_at")
							.substring(0, 10));
					map.put("view_count",
							itemJsonObject.getString("view_count"));
					map.put("delivery_deadline",
							itemJsonObject.getString("delivery_deadline")
									.substring(0, 10));
					map.put("delivery_count", "0");

					taskList.add(map);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return taskList;
	}

	/**
	 * 我收藏的任务
	 * 
	 * @param page
	 * @param context
	 * @return
	 */
	public static ArrayList<HashMap<String, Object>> getMyFocus(int page,
			Context context) {
		ArrayList<HashMap<String, Object>> taskList = new ArrayList<HashMap<String, Object>>();
		String urlString = ConfigInc.getServiceAdress(context)
				+ "user/myfocus?";
		HttpUtils httpUtils = HttpUtils.getInstance();

		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);

		Map<String, String> params = new HashMap<String, String>();

		params.put("page", "" + page);
		params.put("token", users.get(0).getToken());
		try {
			String strJson = httpUtils.httpGet(urlString, params, context);
			JSONObject jsonObject = new JSONObject(strJson);
			String resCode = jsonObject.getString("code");

			JSONObject jsondata = new JSONObject(jsonObject.getString("data"));

			JSONArray jsonArray = jsondata.getJSONArray("data");

			// 对返回的数据进行判断
			if (resCode.equals("1000")) {
				if (jsonArray.length() > 0) {
					for (int i = 0; i < jsonArray.length(); i++) {
						HashMap<String, Object> map = new HashMap<String, Object>();
						JSONObject itemJsonObject = jsonArray.optJSONObject(i);

						map.put("focus_id",
								itemJsonObject.getString("focus_id"));
						map.put("id", itemJsonObject.getString("id"));
						map.put("title", itemJsonObject.getString("title"));
						map.put("bounty", itemJsonObject.getString("bounty"));
						map.put("created_at",
								itemJsonObject.getString("created_at")
										.substring(0, 10));
						map.put("view_count",
								itemJsonObject.getString("view_count"));
						map.put("delivery_count",
								itemJsonObject.getString("delivery_count"));

						map.put("cate_name",
								itemJsonObject.getString("category_name"));

						taskList.add(map);
					}
				} else {
					Toast.makeText(context, "无数据", Toast.LENGTH_SHORT).show();
				}
			} else {
				Toast.makeText(context, "请求异常", Toast.LENGTH_SHORT).show();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return taskList;
	}

	/**
	 * 收藏任务
	 * 
	 * @param tasId
	 * @param context
	 * @return
	 */
	public static int addTaskFocus(String tasId, Context context) {
		int intResult = 0;

		String urlString = ConfigInc.getServiceAdress(context)
				+ "user/addFocus?";
		HttpUtils httpUtils = HttpUtils.getInstance();

		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);

		Map<String, String> params = new HashMap<String, String>();
		params.put("task_id", "" + tasId);
		params.put("token", "" + users.get(0).getToken());

		try {
			String strJson = httpUtils.httpGet(urlString, params, context);
			JSONObject jsonObject = new JSONObject(strJson);
			intResult = Integer.valueOf(jsonObject.getString("code"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return intResult;
	}

	/**
	 * 删除我收藏的某个任务
	 * 
	 * @param tasId
	 * @param context
	 * @return
	 */
	public static int delTaskFocus(String tasId, Context context) {
		int intResult = 0;

		String urlString = ConfigInc.getServiceAdress(context)
				+ "user/deleteFocus";
		HttpUtils httpUtils = HttpUtils.getInstance();

		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);

		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("id", tasId));
		params.add(new BasicNameValuePair("token", users.get(0).getToken()));

		try {
			String strJson = httpUtils.executeRequest(urlString, params);
			JSONObject jsonObject = new JSONObject(strJson);
			intResult = Integer.valueOf(jsonObject.getString("code"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return intResult;
	}

	/**
	 * 赏金托管之余额支付
	 * 
	 * @param taskId
	 * @param intType
	 * @param strPwd
	 * @param context
	 */
	public static String[] bountyByBalance(String taskId, int intType,
			String strPwd, Context context) {
		String strRes[] = new String[2];
		String urlString = ConfigInc.getServiceAdress(context)
				+ "pay/bountyByBalance";
		HttpUtils httpUtils = HttpUtils.getInstance();

		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);

		Log.e("taskId", taskId);
		Log.e("intType", "" + intType);
		Log.e("password", strPwd);
		Log.e("token", users.get(0).getToken());

		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("task_id", taskId));
		params.add(new BasicNameValuePair("pay_type", "" + intType));
		params.add(new BasicNameValuePair("password", strPwd));
		params.add(new BasicNameValuePair("token", users.get(0).getToken()));

		try {
			String strJson = httpUtils.executeRequest(urlString, params);
			JSONObject jsonObject = new JSONObject(strJson);

			Log.e("strJson", strJson);

			strRes[0] = jsonObject.getString("code");
			strRes[1] = jsonObject.getString("message");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return strRes;
	}

	/**
	 * 第三方支付
	 * 
	 * @param strTitle
	 * @param strCash
	 * @param strType
	 * @param strTaskId
	 * @param context
	 * @return
	 */
	public static String postCash(String strTitle, String strCash,
			String strType, String strTaskId, Context context) {
		String strRes = null;
		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);

		String urlString = ConfigInc.getServiceAdress(context)
				+ "user/postCash";
		HttpUtils httpUtils = HttpUtils.getInstance();

		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("title", strTitle));
		params.add(new BasicNameValuePair("cash", strCash));
		params.add(new BasicNameValuePair("pay_type", strType));
		params.add(new BasicNameValuePair("token", users.get(0).getToken()
				.toString()));

		params.add(new BasicNameValuePair("note", strTitle));

		if (StrFormat.formatStr(strTaskId)) {
			params.add(new BasicNameValuePair("task_id", strTaskId));
		}

		try {
			String strJson = httpUtils.executeRequest(urlString, params);

			Log.e("strJson", strJson);

			JSONObject jsonObject = new JSONObject(strJson);
			String resString = jsonObject.getString("code");

			// 对返回的数据进行判断
			if (resString.equals("1000")) {
				JSONObject jsondata = new JSONObject(
						jsonObject.getString("data"));

				if (strType.equals("alipay")) {
					strRes = jsondata.getString("payParam").toString();
				} else {
					strRes = jsondata.getString("params").toString();
				}

			}

		} catch (Exception e) {
			e.printStackTrace();
		}
		return strRes;
	}

	// 招标任务保存付款方式
	public static String[] postPayType(String strTaskId, int payType,
			String strDesc, String append, String again, Context context) {
		String strRes[] = new String[2];
		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);

		String urlString = ConfigInc.getServiceAdress(context)
				+ "myTask/postPayType";
		HttpUtils httpUtils = HttpUtils.getInstance();

		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("token", users.get(0).getToken()));
		params.add(new BasicNameValuePair("task_id", strTaskId));
		params.add(new BasicNameValuePair("pay_type", "" + payType));
		params.add(new BasicNameValuePair("desc", strDesc));

		if (payType == 4) {
			params.add(new BasicNameValuePair("pay_type_append", append));
		}

		params.add(new BasicNameValuePair("submit_again", again));

		try {
			String strJson = httpUtils.executeRequest(urlString, params);

			Log.e("strJson", strJson);
			JSONObject jsonObject = new JSONObject(strJson);

			strRes[0] = jsonObject.getString("code");
			strRes[1] = jsonObject.getString("message");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return strRes;
	}

	// 招标任务威客同意或拒绝付款方式
	public static String[] dealPayType(String strTaskId, String payType,
			Context context) {
		String strRes[] = new String[2];
		db = ConfigInc.getCreateDB(context);
		List<UserBean> users = db.findAll(UserBean.class);

		String urlString = ConfigInc.getServiceAdress(context)
				+ "myTask/dealPayType?";
		HttpUtils httpUtils = HttpUtils.getInstance();

		Map<String, String> params = new HashMap<String, String>();
		params.put("token", users.get(0).getToken());
		params.put("task_id", strTaskId);
		params.put("type", payType);

		try {
			String strJson = httpUtils.httpGet(urlString, params, context);
			JSONObject jsonObject = new JSONObject(strJson);

			strRes[0] = jsonObject.getString("code");
			strRes[1] = jsonObject.getString("message");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return strRes;
	}
}
